package com.sgcc.fj.pmos.e_fj_mall.presenter;

import com.sgcc.fj.pmos.common.base.BasePresenter;
import com.sgcc.fj.pmos.common.bean.BaseResponse;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.e_fj_mall.contract.AuthorizeContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class AuthprizePresenter extends BasePresenter<AuthorizeContract.View> implements AuthorizeContract.Presenter{
    /**
     * 发送短信验证码
     */
    @Override
    public void sendMessageCode () {
        Map<String, Object> params = new HashMap<>();
        HttpRequestUtils.getInstance().request(params, HttpInterConst.ORDER_SENDMESSAGE, new MvpNetCallback<BaseResponse>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                if (!isViewAttached()) {
                    return;
                }
                // 失败回调 判断界面是否销毁
                getView().sendMessageCodeFailed();
            }

            @Override
            public void onResponse(BaseResponse response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().sendMessageCodeSuccess(response);
            }
        });
    }
    /**
     * 发送短信验证码
     */
    @Override
    public void sendMessageCodeNew () {
        Map<String, Object> params = new HashMap<>();
        params.put("flag","0");
        params.put("_t", System.currentTimeMillis());
        HttpRequestUtils.getInstance().request(params, HttpInterConst.ORDER_SENDMESSAGE_NEW, new MvpNetCallback<BaseResponse>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                if (!isViewAttached()) {
                    return;
                }
                // 失败回调 判断界面是否销毁
                getView().sendMessageCodeFailed();
            }

            @Override
            public void onResponse(BaseResponse response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().sendMessageCodeSuccess(response);
            }
        });
    }
    @Override
    public void verifyCode(String code) {
        Map<String, Object> params = new HashMap<>();
        params.put("_t", System.currentTimeMillis());
        params.put("code", code);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.ORDER_VERIFYCODE, new MvpNetCallback<BaseResponse>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                if (!isViewAttached()) {
                    return;
                }
                // 失败回调 判断界面是否销毁
                getView().verifyCodeFailed();
            }

            @Override
            public void onResponse(BaseResponse response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().verifyCodeSuccess(response);
            }
        });
    }
}
